/*
 * @Author: 杨光辉(GerhardYang)
 * @Date: 2021-10-15 10:01:32
 * @LastEditors: 杨光辉(GerhardYang)
 * @LastEditTime: 2021-10-15 10:12:55
 * @Description: file content
 * @Copyright: 超图软件华中平台客户中心 (SuperMap Software Co., Ltd. -Central China Platform)
 */
/* eslint-disable no-unused-vars */
import L from "leaflet";

L.Control.Legend = L.Control.extend({
  options: {
    position: "topright", //初始位置
  },
  initialize: function (options) {
    L.Util.extend(this.options, options);
  },

  onAdd: function (map) {
    this._container = L.DomUtil.create("div", "legend-pane");
    this._container.style.display = "none";
    let legendheader = document.createElement("div");
    legendheader.className = "legend-head";
    legendheader.innerHTML = "<div><h3>图例</h3></div>";
    this._container.appendChild(legendheader);
    let legendcontent = document.createElement("div");
    legendcontent.className = "legend-content";

    this._container.appendChild(legendcontent);

    return this._container;
  },
  onRemove: function (map) {
    // Nothing to do here
  },
});

const Legend = function (opts) {
  return new L.Control.Legend(opts);
};
const updataLegend = function (data, legend) {
  var boxObj = document.getElementsByClassName("legend-content")[0];
  document.getElementsByClassName("legend-pane")[0].style.display = "block";

  let insertul = document.createElement("div");
  insertul.style.marginTop = "10px";
  insertul.className = `leaflet-legend-${data.key}`;
  let string = "";

  legend.map((item) => {
    string =
      string +
      `<tr  ><td><img  style="width:25px;height:25px" src='${item.legendurl}'/></td><td ><span style=" margin-left: 20px;">${item.name}</span></td></tr></br>`;
  });
  insertul.innerHTML = string;
  boxObj.appendChild(insertul);
};
const deleteLgend = function (data) {
  var boxObj = document.getElementsByClassName("legend-content")[0];
  boxObj.innerHTML = "";
  document.getElementsByClassName("legend-pane")[0].style.display = "none";
};
export { Legend, updataLegend, deleteLgend };
